ig.module( 
	'game.main' 
)
.requires(
	
	'impact.game',
	'impact.font',
	
	'game.camera',
	'game.entities.blob',
	'game.entities.player',
	'game.entities.grunt',
	'game.entities.hurt',
	'game.entities.crate',
	'game.entities.spewer',
	'game.entities.dropper',
	'game.entities.factory',
	'game.entities.kami',
	'game.levels.test'
	
)
.defines(function(){

MyGame = ig.Game.extend({
	gravity: 240,
        player: null,
        mode: 0,
        lastCheckpoint: null,
        playerSpawnPos: {
            x: 0,
            y: 0
        },
	camera: null,
	room: null,
	
	// Load a font
	font: new ig.Font( 'media/04b03.font.png' ),
	
	
	init: function() {		
		// Initialize your game here; bind keys etc.
		ig.input.bind(ig.KEY.LEFT_ARROW, 'left');
                ig.input.bind(ig.KEY.RIGHT_ARROW, 'right');
                ig.input.bind(ig.KEY.UP_ARROW, 'jump');
                ig.input.bind(ig.KEY.C, 'shoot');

		this.camera = new Camera(ig.system.width / 4, ig.system.height / 3, 5);
		this.camera.trap.size.x = ig.system.width / 10;
		this.camera.trap.size.y = ig.system.height / 3;
		this.camera.lookAhead.x = ig.ua.mobile ? ig.system.width / 6 : 0;

		this.loadLevel(LevelTest);
		
		this.setPlayer( this.getEntitiesByType( EntityPlayer )[0]);
	},
	loadLevel: function (level) {
            this.parent(level);
        },
	
	setPlayer: function( player ){
            this.player = player;
            this.lastCheckpoint = null;
            this.playerSpawnPos = {
                x: this.player.pos.x,
                y: this.player.pos.y
            };
            this.camera.max.x = this.collisionMap.width * this.collisionMap.tilesize - ig.system.width;
            this.camera.max.y = this.collisionMap.height * this.collisionMap.tilesize - ig.system.height;
            this.camera.set(this.player);		
	},
        update: function () {
            if( this.player )
		this.camera.follow(this.player);
            this.parent();
        },
	draw: function () {
            this.parent();
            this.camera.draw();
        }
});


// Start the Game with 60fps, a resolution of 320x240, scaled
// up by a factor of 2
ig.main( '#canvas', MyGame, 60, 320, 240, 2 );

});
